package com.tianbao54.thrift;

import com.tianbao54.thrift.model.Person;
import com.tianbao54.thrift.model.PersonService;
import org.apache.thrift.protocol.TCompactProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TFramedTransport;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransport;

public class ThriftClient {

    public static void main(String[] args) {

        TTransport transport = new TFramedTransport(new TSocket("localhost",8888),600);
        TProtocol protocol = new TCompactProtocol(transport);
        PersonService.Client client = new PersonService.Client(protocol);

        try {
            transport.open();
            Person person = client.getPersonByPersonName("zhangsan");
            System.out.println(person);
            client.savePerson(new Person().setAge(12).setMarried(false).setName("lisi"));
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            transport.close();
        }
    }
}
